clear
set more			 off
cap   log close 		_all

log using 	"../log/A0_persid_varsel.log", replace 


clear
set more			 off
cap   log close 		_all

log using 	"../log/A1_clean_varseldata.log", replace 
use 		"$datapath/rawdata/DS_Lev_AF_hist_varsel.dta"


{ // Generate a list of persid in this dataset 
********************************************************************************
* This dataset with persid of alla indiviuals getting notifications is to be 
* used when collecting data from the RAMS register (Jobb_[year].dta) in 
* A0_append_RAMS.do This is needed in order to keep down the otherwise hughe 
* sample size.
use 		"$rawdatapath/DS_Lev_AF_hist_varselperson.dta",clear

*Drop duplicates
duplicates drop lopnr, force
keep lopnr

*Append 2016-2019 data
preserve
	use "$rawdatapath/varsel_ftg_20152019.dta",clear
	
	*Merge on workers
	merge 1:m lopnr_varsellnr lopnr_hist_varsellnr using "$rawdatapath/varsel_ind_20152019.dta"
	keep if _merge==3 // again no worries for _merge==1
	drop _merge
	
	gen year = year(ankomst_dat)
	keep if inrange(year,2016,2019)
	drop year
	
	keep lopnr
	duplicates drop lopnr, force
	keep lopnr
	
	*Save data
	tempfile temp
	save `temp'
restore
append using `temp'

*Drop duplicates
duplicates drop lopnr, force
keep lopnr

*Rename to match name in RAMS data
save "$datapath/A0_persid_varsel.dta", replace

}
*

log close
